package com.example.everying.service.user.impl;/*
 * 项目名称: everything
 * 文件名: InviteCodeServiceImpl
 * 作者: 张泽阳
 * 日期: 2025/5/26
 * 描述:
 */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.everying.mapper.invite.InviteCodeMapper;
import com.example.everying.model.entity.invite.InviteCodeEntity;
import com.example.everying.service.user.InviteCodeService;
import org.springframework.stereotype.Service;

@Service
public class InviteCodeServiceImpl extends ServiceImpl<InviteCodeMapper, InviteCodeEntity> implements InviteCodeService {
    /**
     * 根据邀请码查询邀请码
     * @param code 邀请码
     * @return 邀请码
     */
    @Override
    public InviteCodeEntity getInviteCodeByCode(String code) {
        LambdaQueryWrapper<InviteCodeEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(InviteCodeEntity::getInviteCode, code);
        queryWrapper.eq(InviteCodeEntity::getStatus, 1);
        if (getOne(queryWrapper) == null) {
            return null;
        }
        return getOne(queryWrapper);
    }

    @Override
    public InviteCodeEntity getInviteCodeByOwnerId(String userId) {
        LambdaQueryWrapper<InviteCodeEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(InviteCodeEntity::getOwnerId, userId);
        if (getOne(queryWrapper) == null){
            InviteCodeEntity inviteCode = new InviteCodeEntity();
            inviteCode.setInviteCode(" ");
        }
        return getOne(queryWrapper);
    }
}
